# src/context.py
import os
import shutil
import tempfile

def _ignore_patterns():
    return shutil.ignore_patterns(".git", ".DS_Store", "__pycache__", "*.log")

def prepare_context(project_info):
    """
    准备构建上下文：
      - 直接把 go_path 的内容复制到 context 根目录（复刻原项目结构）
    """
    context_dir = tempfile.mkdtemp(prefix="gopack_")
    src_root = project_info.get("go_path") or os.path.dirname(project_info["entry"])
    shutil.copytree(src_root, context_dir, dirs_exist_ok=True, ignore=_ignore_patterns())
    return context_dir
